﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using LDSP.BRL;

namespace ImplementationInitialization
{
    public class ImportResult
    {
        public DataTable CodificationItemResult { get; set; }
        public DataTable StandardItemResult { get; set; }
        public DataTable CodificationAttachmentResult { get; set; }
        public DataTable StandardAttachmentResult { get; set; }

        public ImportResult()
        {
            CodificationItemResult = InitialResultItemTable();
            CodificationAttachmentResult = InitialAttachmentTable();
            StandardItemResult = InitialResultItemTable();
            StandardAttachmentResult = InitialAttachmentTable();
        }

        private DataTable InitialResultItemTable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_EXCEL_FILE);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_EXCEL_SHEET);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_TYPE);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_ITEM_NAME);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_MESSAGE);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_SUCCESS);

            return dt;
        }

        private DataTable InitialAttachmentTable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_ITEM_NAME);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_TYPE);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_MESSAGE);
            dt.Columns.Add(Constants.ImportResultColumnNames.COL_SUCCESS);

            return dt;
        }

        public void AddItemResult(string excelFile, DocType type, string excelSheet, string name, string message, bool success)
        {
            DataTable dt = type == DocType.法律法规 ? CodificationItemResult : StandardItemResult;
            string s = success ? "成功" : "失败";

            dt.Rows.Add(excelFile, excelSheet, type.ToString(), name, message, s);
        }

        public void AddAttachmentResult(string name, DocType type, string message, bool success)
        {
            DataTable dt = type == DocType.法律法规 ? CodificationAttachmentResult : StandardAttachmentResult;
            string s = success ? "成功" : "失败";

            dt.Rows.Add(name, type.ToString(), message, s);
        }

        public void ClearCodification()
        {
            CodificationItemResult.Rows.Clear();
            CodificationAttachmentResult.Rows.Clear();
        }

        public void ClearStandard()
        {
            StandardItemResult.Rows.Clear();
            StandardAttachmentResult.Rows.Clear();
        }

        public void ClearAll()
        {
            ClearCodification();
            ClearStandard();
        }
    }
}
